enum Color{
    Red = 1,
    Green = 2,
    Blue = 3
}

let colorName : string  = Color[3];
let colorValue : number = Color.Blue;

// alert(colorName+": ${colorValue}")


let names : any = 4
let isFixed = names.toFixed()
alert("  isFixed: "+isFixed)

// 类型强转（断言）
let someValue : any = "this is me"
// let size : number = (<string>someValue).length
let size : number = someValue.length;
alert(size)
// console.log(isFied)

// var和let作用域问题探讨
// var 
for (var i = 0; i < 10; i++) {
    setTimeout(function() { console.log("var : "+i); }, 100 * i);
}

// let 
for (let i = 0; i < 10; i++) {
    setTimeout(function() { console.log("let : "+i); }, 100 * i);
}

interface LabelledValue{
     name:string;
}

function printlnLabelled(labell:LabelledValue){
    console.log(labell.name)
}

let lab =  {name:"my name is xioaming"};
printlnLabelled(lab)

// 可选属性

interface SquareConfig {
    color?: string;
    width?: number;
  }
  
  function createSquare(config: SquareConfig): {color: string; area: number} {
    let newSquare = {color: "white", area: 100};
    if (config.color) {
      newSquare.color = config.color;
    }
    if (config.width) {
      newSquare.area = config.width * config.width;
    }
    return newSquare;
  }
  
  let mySquare = createSquare({color: "black"});
  alert(mySquare.color)

  // 只读属性
  interface Paint{
      readonly x: number;
      readonly y: number
      
  }

  // 使用
  let paint: Paint = { x: 1, y: 2 };

